class Base {
    isEmpty(params) {
        //1.判断params 是对象还是数组
        if (Array.isArray(params)) {
            return params.length ? params.length : "数组为空"
        }
        else {
            return Object.keys(params).length ? Object.keys(params).length : "对象为空";
        }
    }
}
const fs = require('fs')
const path = require('path')
class Util extends Base {
    constructor(options) {
        super(options)
    }
    loadJs(path) {
        return this.readFile(path)
    }
    loadCss(path) {
        return this.readFile(path)
    }
    loadImg(path) {
        return this.readFile(path, 'base64')
    }
    readFile(path, type) {
        return new Promise((resolve, reject) => {
            fs.readFile(path, type, (error, data) => {
                if (error) {
                    reject(error);
                } else {
                    resolve(data);
                }
            })
        })
    }
    async init(arr) {
        let res = []

        for (let i = 0; i < arr.length; i++) {
            //分情况读取文件
            let extname = path.extname(arr[i]).slice(1)
            extname = /^(jpg|png)$/.test(extname) ? 'img' : extname

            let type = extname[0].toUpperCase() + extname.slice(1)
            type = `load${type}`
            let data = await this[type](arr[i])
            res.push(data)
        }
        return res
    }
}

let util = new Util();
console.log(util.isEmpty([1,2,3]))
console.log(util.isEmpty({name:"123"}))
util.init(['./src/index.js', './src/index.css','./src/Sketchpad.png']).then(res => {
    console.log(res)
})